# initial intervention costs
ideo_cost_mid = 356000
ideo_cost_low = ideo_cost_mid * 0.5
ideo_cost_high = ideo_cost_mid * 1.5

# implementation costs
low_cost = 0.1 # in USD
mid_cost = 1 # in USD
high_cost = 100 # in USD

# number of persons reached
x_personsreached_low <- seq(1, 100, 1)
x_personsreached_mid <- seq(10, 1000, 10)
x_personsreached_high <- seq(100, 10000, 100)

# daly per person
y_dalypp <- seq(0.005, 0.5, 0.005)

# icer based on cost and reach
# low cost
z_icer_lc_lr <- ((ideo_cost_low + low_cost * x_personsreached_low)/x_personsreached_low)/y_dalypp
z_icer_lc_mr <- ((ideo_cost_low + low_cost * x_personsreached_mid)/x_personsreached_mid)/y_dalypp
z_icer_lc_hr <- ((ideo_cost_low + low_cost * x_personsreached_high)/x_personsreached_high)/y_dalypp

# mid cost
z_icer_mc_lr <- ((ideo_cost_mid + mid_cost * x_personsreached_low)/x_personsreached_low)/y_dalypp
z_icer_mc_mr <- ((ideo_cost_mid + mid_cost * x_personsreached_mid)/x_personsreached_mid)/y_dalypp
z_icer_mc_hr <- ((ideo_cost_mid + mid_cost * x_personsreached_high)/x_personsreached_high)/y_dalypp

# high cost
z_icer_hc_lr <- ((ideo_cost_high + high_cost * x_personsreached_low)/x_personsreached_low)/y_dalypp
z_icer_hc_mr <- ((ideo_cost_high + high_cost * x_personsreached_mid)/x_personsreached_mid)/y_dalypp
z_icer_hc_hr <- ((ideo_cost_high + high_cost * x_personsreached_high)/x_personsreached_high)/y_dalypp
# plot labels
x_axis <- list(
    showgrid = T,
    title = "Individuals reached",
    mirror = "all"
)

y_axis <- list(
    showgrid = T,
    title = "DALYs averted per individual reached",
    mirror = "all"
)

Low cost / low reach

icer_lc_lr <- data.frame(x_personsreached_low,
                         y_dalypp,
                         z_icer_lc_lr)

icer_lc_lr %>% 
    plot_ly(x = x_personsreached_low,
            y = y_dalypp,
            z = z_icer_lc_lr,
            colorscale = "Jet",
            type = "contour",
            autocontour = F,
            contours = list(
                start = 0,
                end = 4000,
                size = 500#,
                #coloring = "heatmap"
                )
    ) %>%
    layout(title = "Low Intervention Cost",
           xaxis = x_axis,
           yaxis = y_axis)

Low cost / mid reach

icer_lc_mr <- data.frame(x_personsreached_mid,
                         y_dalypp,
                         z_icer_lc_mr)

icer_lc_mr %>% 
    plot_ly(x = x_personsreached_mid,
            y = y_dalypp,
            z = z_icer_lc_mr,
            colorscale = "Jet",
            type = "contour",
            autocontour = F,
            contours = list(
                start = 0,
                end = 4000,
                size = 500)
    ) %>%
    layout(title = "Low Intervention Cost",
           xaxis = x_axis,
           yaxis = y_axis)

Low cost / high reach

icer_lc_hr <- data.frame(x_personsreached_high,
                         y_dalypp,
                         z_icer_lc_hr)

icer_lc_hr %>% 
    plot_ly(x = x_personsreached_high,
            y = y_dalypp,
            z = z_icer_lc_hr,
            colorscale = "Jet",
            type = "contour",
            autocontour = F,
            contours = list(
                start = 0,
                end = 4000,
                size = 500)
    ) %>%
    layout(title = "Low Intervention Cost",
           xaxis = x_axis,
           yaxis = y_axis)

Mid cost / low reach

icer_mc_lr <- data.frame(x_personsreached_low,
                         y_dalypp,
                         z_icer_mc_lr)

icer_mc_lr %>% 
    plot_ly(x = x_personsreached_low,
            y = y_dalypp,
            z = z_icer_mc_lr,
            colorscale = "Jet",
            type = "contour",
            autocontour = F,
            contours = list(
                start = 0,
                end = 4000,
                size = 500)
    ) %>%
    layout(title = "Medium Intervention Cost",
           xaxis = x_axis,
           yaxis = y_axis)

Mid cost / mid reach

icer_mc_mr <- data.frame(x_personsreached_mid,
                         y_dalypp,
                         z_icer_mc_mr)

icer_mc_lr %>% 
    plot_ly(x = x_personsreached_mid,
            y = y_dalypp,
            z = z_icer_mc_mr,
            colorscale = "Jet",
            type = "contour",
            autocontour = F,
            contours = list(
                start = 0,
                end = 4000,
                size = 500)
    ) %>%
    layout(title = "Medium Intervention Cost",
           xaxis = x_axis,
           yaxis = y_axis)

Mid cost / high reach

icer_mc_hr <- data.frame(x_personsreached_high,
                         y_dalypp,
                         z_icer_mc_hr)

icer_mc_lr %>% 
    plot_ly(x = x_personsreached_high,
            y = y_dalypp,
            z = z_icer_mc_hr,
            colorscale = "Jet",
            type = "contour",
            autocontour = F,
            contours = list(
                start = 0,
                end = 4000,
                size = 500)
    ) %>%
    layout(title = "Medium Intervention Cost",
           xaxis = x_axis,
           yaxis = y_axis)

High cost / low reach

icer_hc_lr <- data.frame(x_personsreached_low,
                         y_dalypp,
                         z_icer_hc_lr)

icer_hc_lr %>% 
    plot_ly(x = x_personsreached_low,
            y = y_dalypp,
            z = z_icer_hc_lr,
            colorscale = "Jet",
            type = "contour",
            autocontour = F,
            contours = list(
                start = 0,
                end = 4000,
                size = 500)
    ) %>%
    layout(title = "High Intervention Cost",
           xaxis = x_axis,
           yaxis = y_axis)

High cost / mid reach

icer_hc_mr <- data.frame(x_personsreached_mid,
                         y_dalypp,
                         z_icer_hc_mr)

icer_hc_lr %>% 
    plot_ly(x = x_personsreached_mid,
            y = y_dalypp,
            z = z_icer_hc_mr,
            colorscale = "Jet",
            type = "contour",
            autocontour = F,
            contours = list(
                start = 0,
                end = 4000,
                size = 500)
    ) %>%
    layout(title = "High Intervention Cost",
           xaxis = x_axis,
           yaxis = y_axis)

High cost / high reach

icer_hc_hr <- data.frame(x_personsreached_high,
                         y_dalypp,
                         z_icer_hc_hr)

icer_hc_lr %>% 
    plot_ly(x = x_personsreached_high,
            y = y_dalypp,
            z = z_icer_hc_hr,
            colorscale = "Jet",
            type = "contour",
            autocontour = F,
            contours = list(
                start = 0,
                end = 4000,
                size = 500)
    ) %>%
    layout(title = "Medium Intervention Cost",
           xaxis = x_axis,
           yaxis = y_axis)